package com.example.xposed;

import android.util.Log;

import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage;

public class HookTest implements IXposedHookLoadPackage {
    @Override
    public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
        String packageName = "com.example.xposeddemo";
        Log.e("HookTest", "handleLoadPackage packageName:" + packageName + " lpparam.packageName: " + lpparam.packageName);
        if (packageName.equals(lpparam.packageName)) {
            XposedBridge.log("hook 到应用了");
            Class clazz = lpparam.classLoader.loadClass(packageName + ".MainActivity");
            XposedHelpers.findAndHookMethod(clazz, "showToast",String.class, new XC_MethodHook() {
                @Override
                protected void beforeHookedMethod(MethodHookParam param) throws Throwable {

                    param.args[0]= "被劫持了";
                }

                @Override
                protected void afterHookedMethod(MethodHookParam param) throws Throwable {

                }
            });
        }
    }
}
